<template>
    <div class="house-wrapper">
        <div class="view">
            <div class="search-view">
                <div class="search">
                    <span>人员：</span>
					<Input v-model="name" placeholder="请输入姓名" style="width: 150px;" />
                </div>
                <div class="search">
                    <Button
                        type="primary"
                        :loading="isLoading"
                        @click="clickSearch">搜索
                    </Button>
                </div>
                 <div class="search fr">
                    <Button 
                        type="primary" 
                        @click="clickAdd">
                        添加权限
                    </Button>
                </div>
            </div>
            <div class="main-view">
                <RoleManageList 
                    :data="listData"
                    @on-action="clickAction">
                </RoleManageList>
            </div>
            <div class="page-view">
                <PageView
                    :data="pageData"
                    @on-change-page="changePage"
                    @on-change-pagesize="changePagesize">
                </PageView>
		    </div>
             <!-- 新增操作弹框 -->
            <div v-if="addData.isShow">
                <RoleModal
                    :data="addData"
                    @on-submit="submitAction">
                </RoleModal>
            </div>
            <!-- 密码重置弹框 -->
            <div v-if="resetData.isShow">
                <RoleResetModal
                    :data="resetData"
                    @on-reset="submitReset">
                </RoleResetModal>
            </div>
        </div>
    </div>
</template>

<script>

import RoleManageList from '@/view/roleManage/list/RoleManageList'
import RoleModal from '@/view/roleManage/list/RoleModal'
import RoleResetModal from '@/view/roleManage/list/RoleResetModal'
import PageView from '@/components/Page'

export default {
    components: {
        RoleManageList,
        RoleModal,
        RoleResetModal,
        PageView
    },
    data () {
        return {
            isLoading: false,
            name: '',
            addData: {
				actionType: 1,
				isShow: false,
				row: null,
				data: {}
			},
            resetData: {
				isShow: false,
				row: null,
				data: {}
			},
            listData: {
                isLoading: false,
				data: [
                    {id: 1, name: '张三', quan: '权限', guan: '会议室', time: '里斯', person: '里斯', num: '2222222'}
                ]
            },
            pageData: {
				currentPage: 0,
				pagesize: 20,
				totalSize: 0
            },
            options1: {
                disabledDate (date) {
                    return date && date.valueOf() < Date.now() - 86400000;
                }
            },
            options2: {
                disabledDate: date => {
                    return (date && date.valueOf() < new Date(this.roomData.startTime));
                }
            },
        };
    },
    methods: {
        changePage(page) {
            this.pageData.currentPage = page - 1;
            // this.getRoomList()
        },
        changePagesize(pagesize) {
            this.pageData.pagesize = pagesize;
            // this.getRoomList()
        },
        getRoomList(){ 
            // this.listData.isLoading = true
            // companyService.getQuestionList(this.data, this.pageData.currentPage, this.pageData.pageSize).then(res=>{
            // this.listData.isLoading = false             
            //     let result = res.data
            //     let code = result.rescode
            //     let resmsg = result.msg
            //     if(code == 100){
            //         if(result.data){
            //             this.listData.data = result.data
            //         } else {
            //             this.listData.data = []
            //         }
            //         this.pageData.totalSize = result.totalSize
            //     } else {
            //         this.$Message.error(resmsg)
            //     }
            // }, res=>{
            //     this.listData.isLoading = false                
            //     this.$Message.error('服务器异常，请稍后再试！')
            // })
        },
        clickAdd(){
            this.addData.actionType = 1
            this.addData.isShow = true
            this.addData.row = null
            this.addData.data = {}
        },
        clickAction(type, formData){
            // console.log(type)
            // console.log(formData)
            switch(type) {
                case 'edit': 
                    this.addData.actionType = 2
                    this.addData.isShow = true
                    this.addData.data = formData
                    this.addData.row = formData
                break;
                case 'reset':
                    this.resetData.isShow = true
                    this.resetData.data = formData
                    this.resetData.row = formData
                break;
            }
        },
        clickSearch(){
            // this.getRoomList()
        },
        changeStart(value){
            this.roomData.startTime = value
        },
        changeEnd(value){
            this.roomData.endTime = value
        },
        submitAction(formData) {
            // companyService.questionSave(formData.data).then(res=>{
            //     let result = res.data
            //     let code = result.rescode
            //     let resmsg = result.msg
            //     if(code == 100){
            //         this.$Message.success(resmsg)
            //         formData.isShow = false
            //         this.getRoomList()
            //     } else {
            //         this.$Message.error(resmsg)
            //     }
            // }, res=>{
            //     this.$Message.error('服务器异常，请稍后再使！')
            // })
        },
        submitReset(formData){
            // console.log(formData)
            // companyService.questionDel(formData.id).then(res=>{
            //     // console.log(formData.id)
            //     let result = res.data
            //     let code = result.rescode
            //     let resmsg = result.msg
            //     if(code == 100){
            //          this.$Message.success(resmsg)
                        // formData.isShow = false
                        // this.$Message.success('密码修改成功')

            //         this.getProblemList()                    
            //     } else {
            //         this.$Message.error(resmsg)
            //     }
            // }, res => {
            //     this.$Message.error('服务器异常，请稍后再试！')
            // })
        }
    }
};
</script>

<style lang="less" scoped>
    .house-wrapper {
        padding: 40px 20px;
        .view {
            background: #fff;
            border: 1px solid #e6e6e6;
            padding: 30px 20px;
            .search-view {
                margin-bottom: 35px;
                .search {
                    margin-right: 30px;
                    display: inline-block;
                }
            }
        }
    }
</style>
